**************************************************************************************************************
**	Replication do-file for "Social Democracy and the Birth of Working-Class Representation in Europe"
**  Purpose: Produce all the regressions for Norway & marginal effects plots (Figures 4 & 6)
*************************************************************************************************************

/* set the directory */

/********************
*    TABLE 1: SMD
*********************/
use "Norway.dta", clear

reg mp_manual manual_1910_smd                      ///
electoratel union_density mmd i.year if socialist==1 & pr==0 & round1==1

reg mp_manual c.manual_1910_smd##c.manual_1910_smd  ///
electoratel union_density mmd i.year if socialist==1 & pr==0 & round1==1
margins, at(manual_1910_smd=(20 30 40 45 50 60 65 70 75)) /* Produce Figure 4a*/
marginsplot, title("") ///
	 		 ytitle("Predicted Probability of Working-Class Candidate", size(4)) ///
			 xlabel(, labsize(4))  ylabel(, labsize(4))  xtitle(, size(4)) ///
			 addplot(hist manual_1910_smd, yaxis(2) xlabel(20 30 40 45 50 60 65 70 75, ///
			 labsize(4) ) ysc(axis(2) alt)  fcolor(gs6%20) lcolor(gs6%20)) ///
			 legend (order(1 "Worker" 2 "Non-Worker" )) graphregion(color(white)) 

reg elected mp_manual manual_1910_smd               ///
electoratel union_density mmd i.year if socialist==1 & pr==0  & round1==1

reg elected i.mp_manual##c.manual_1910_smd##c.manual_1910_smd ///
electoratel union_density mmd i.year if socialist==1 & pr==0 & round1==1
margins  mp_manual, at(manual_1910_smd=(20 30 40 45 50 55 60 65 70 75)) /* Produce Figure 4b*/
marginsplot, title("") 			 xlabel(, labsize(4))  ylabel(, labsize(4))  xtitle(, size(4)) ///
	 		 ytitle("Predicted Probability of Working-Class Candidate" , size(4)) ///
			 addplot(hist manual_1910_smd, yaxis(2) xlabel(20 30 40 45 50 55 60 65 70 75, labsize(4)) ysc(axis(2) alt) ///
			 fcolor(gs6%20) lcolor(gs6%20)) graphregion(color(white)) legend(col(3))  

*-----------------------
*       TABLE 3: PR
*----------------------
use "Norway.dta", clear

reg seatrank c.manual_1910_pr i.mp_manual   female                 ///
magnitude i.year if pr==1 & socialist==1 & deputy==0 &  rank<=magnitude

reg seatrank c.manual_1910_pr##c.manual_1910_pr##i.mp_manual  ///
magnitude female i.year if pr==1 & socialist==1 & deputy==0 &  rank<=magnitude
margins mp_manual, at(manual_1910_pr=(33 40 45 50 55 59 66 74))  /* Produce Figure 6*/
marginsplot, title("") ///
	 		 ytitle("Predicted Probability of Seat Rank Security") ///
			 addplot(hist manual_1910_pr, yaxis(2)  ysc(axis(2) alt) fcolor(gs6%20) lcolor(gs6%20)) ///
			 graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 legend (order(1 "Worker" 2 "Non-Worker" ))  legend(col(3))

reg seatrank c.union_density mp_manual  female    ///
magnitude i.year if pr==1 & socialist==1 & deputy==0 &  rank<=magnitude

reg seatrank c.union_density##i.mp_manual female  ///
magnitude i.year if pr==1 & socialist==1 & deputy==0 &  rank<=magnitude

*------------------------
*       APPENDIX
*------------------------
*--------------------------------------
*	Appendix: Descriptive statistics 
*--------------------------------------
use "Norway.dta", clear

estpost summarize mp_manual manual_1910_smd union_density  ///
				  electoratel elected mmd if pr==0 & socialist==1 & round1==1

estpost summarize seatrank manual_1910_pr union_density female ///
				 magnitude if pr==1 & socialist==1 & deputy==0 &  rank<=magnitude & seatrank!=.

*------------------------------------------------
*	Appendix: TABLE D Probit models (plurality rule)
*-------------------------------------------------/
use "Norway.dta", clear
keep if pr==0 & round1==1

probit mp_manual manual_1910_smd                      ///
electoratel union_density mmd i.year if socialist==1 & pr==0 
estat ic 

probit mp_manual c.manual_1910_smd##c.manual_1910_smd  ///
electoratel union_density mmd i.year if socialist==1 & pr==0 
estat ic 

probit elected mp_manual manual_1910_smd               ///
electoratel union_density mmd i.year if socialist==1 & pr==0  
estat ic 

probit elected i.mp_manual##c.manual_1910_smd##c.manual_1910_smd ///
electoratel union_density mmd i.year if socialist==1 & pr==0 
estat ic 

*----------------------------------------------------------
*       TABLE E: Plurality W/O the outlier in unionization
*-----------------------------------------------------------
use "Norway.dta", clear

reg mp_manual manual_1910_smd                       ///
union_density electoratel mmd i.year if socialist==1 & pr==0 & round1==1 & union_density<70

reg mp_manual c.manual_1910_smd##c.manual_1910_smd  ///
union_density electoratel mmd i.year if socialist==1 & pr==0 & round1==1 & union_density<70
margins, at(manual_1910_smd=(20 30 40 45 50 60 75))
marginsplot, title("") ///
	 		 ytitle("Marginal Effect of Percent Manual", size(4)) ///
			 xlabel(, labsize(4))  ylabel(, labsize(4))  xtitle(, size(4)) ///
			 addplot(hist manual_1910_smd, yaxis(2) xlabel(20 30 40 45 50 60 75, ///
			 labsize(4) ) ysc(axis(2) alt)  fcolor(gs6%20) lcolor(gs6%20)) ///
			 legend (order(1 "Worker" 2 "Non-Worker" )) graphregion(color(white)) 

reg elected mp_manual manual_1910_smd               ///
union_density  electoratel mmd i.year if socialist==1 & pr==0 & round1==1 & union_density<70 

reg elected i.mp_manual##c.manual_1910_smd##c.manual_1910_smd ///
union_density  electoratel mmd i.year if socialist==1 & pr==0 & round1==1 & union_density<70
margins  mp_manual, at(manual_1910_smd=(20 30 40 45 50 60 75))
marginsplot, title("") 			 xlabel(, labsize(4))  ylabel(, labsize(4))  xtitle(, size(4)) ///
	 		 ytitle("Marginal Effect of Percent Manual" , size(4)) ///
			 addplot(hist manual_1910_smd, yaxis(2) xlabel(20 30 40 45 50 60 75, labsize(4)) ysc(axis(2) alt) ///
			 fcolor(gs6%20) lcolor(gs6%20)) graphregion(color(white)) legend(col(3))  /**/

/*--------------------------------------------------------
	TABLE F: Plurality w/o unionization
--------------------------------------------------------*/
use "Norway.dta", clear
keep if pr==0 & round1==1

reg mp_manual manual_1910_smd                      ///
electoratel mmd i.year if socialist==1 & pr==0  & round1==1

reg mp_manual c.manual_1910_smd##c.manual_1910_smd  ///
electoratel  mmd i.year if socialist==1 & pr==0  & round1==1

reg elected mp_manual manual_1910_smd               ///
electoratel mmd i.year if socialist==1 & pr==0   & round1==1

reg elected i.mp_manual##c.manual_1910_smd##c.manual_1910_smd ///
electoratel mmd i.year if socialist==1 & pr==0  & round1==1

*---------------------------------
*    TABLE G: ALTERNATIVE DV
*---------------------------------
use "Norway.dta", clear
keep if pr==1
keep if rank<=magnitude

replace manual_1910_pr=manual_1910_pr/100
gen altdv=magnitude*manual_1910_pr /* alternative DV. */
replace manual_1910_pr=manual_1910_pr*100

gen gap=altdv-rank
label var gap "Candidate's Seat Guerantee"
ta gap if mp_manual==1
ta gap if mp_manual==0
gr box gap if pr==1 & socialist==1 & deputy==0, by(mp_manual) yline(0, lc(black) lp(dot))  graphregion(fcolor(white)) scheme(s2mono) 

reg gap c.manual_1910_pr i.mp_manual   female                 ///
i.year if pr==1 & socialist==1 & deputy==0 

reg gap c.manual_1910_pr##c.manual_1910_pr##i.mp_manual  ///
female i.year if pr==1 & socialist==1 & deputy==0 
margins mp_manual, at(manual_1910_pr=(30(1)75))  /*produce figure B*/
marginsplot, title("") ///
	 		 ytitle("MPredicted Probability of Seat Guarantee") ///
			 addplot(hist manual_1910_pr, yaxis(2)  ysc(axis(2) alt) fcolor(gs6%20) lcolor(gs6%20)) ///
			 graphregion(fcolor(white) ilcolor(white) lcolor(white)) ///
			 legend (order(1 "Worker" 2 "Non-Worker" ))  legend(col(3))

reg gap c.union_density mp_manual  female    ///
i.year if pr==1 & socialist==1 & deputy==0 & union_density<20

reg gap c.union_density##i.mp_manual female  ///
i.year if pr==1 & socialist==1 & deputy==0 & union_density<20	 